/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Examples;

import homomorphism.list.ThirdHomomorphismTheorem;
import java.util.ArrayList;
import org.apache.hadoop.io.LongWritable;

/**
 *
 * @author takeshi
 */
public class SUM2 extends ThirdHomomorphismTheorem<LongWritable, LongWritable> {

    public static LongWritable sum(ArrayList<LongWritable> xs) {
        Long rst = 0l;
        for (LongWritable var : xs) {
            rst += var.get();
        }
        return new LongWritable(rst);
    }

    public LongWritable fold(ArrayList<LongWritable> values) {
        return sum(values);
    }

    public ArrayList<LongWritable> unfold(final LongWritable value) {
        return new ArrayList<LongWritable>() {

            {
                add(value);
            }
        };
    }
}
